/**
 * 
 */
package qemese.ticketMachine;

import java.util.ArrayList;
import java.util.List;

import qemese.InputReader;
import qemese.ticket.Ticket;

/**
 * @author Pawel
 * 
 */
public class TicketMachine {

	private double totalAmmount; // ilość pieniędzy w maszynie

	private List<Ticket> ticketList;

	public TicketMachine() {
		ticketList = new ArrayList<Ticket>();
		ticketList.add(new Ticket(3, "15 min N"));
		ticketList.add(new Ticket(1.5, "15 min U"));
		ticketList.add(new Ticket(6, "30 min N"));
		ticketList.add(new Ticket(3, "30 min U"));
		ticketList.add(new Ticket(10, "24 h N"));
		ticketList.add(new Ticket(5, "24 h U"));
	}

	public double getTotalAmmount() {
		return totalAmmount;
	}

	public void setTotalAmmount(double totalAmmount) {
		this.totalAmmount = totalAmmount;
	}

	public List<Ticket> getTicketList() {
		return ticketList;
	}

	public void pay(Ticket ticket) {
		System.out.println("Wpłać: ");
		Double currentAmmount = 0.0;
		while (currentAmmount < ticket.getPrice()) {
			InputReader reader = new InputReader();
			currentAmmount += Double.parseDouble(reader.read());
			if (currentAmmount > ticket.getPrice()) {
				totalAmmount += ticket.getPrice();
				System.out.println("Zakupiono bilet");
				System.out.println("Reszta: "
						+ (currentAmmount - ticket.getPrice()));
			} else if (currentAmmount == ticket.getPrice()) {
				System.out.println("Zakupiono bilet");
				totalAmmount += currentAmmount;
			} else {
				System.out.println("Za mała kwota. Pozostało do zapłaty: " + (ticket.getPrice() - currentAmmount) );
			}
		}
	}
}
